import * as apiService from '@/services/api';

/**
 * 获取会员列表
 * @param params
 * @returns {Promise<*>}
 *
 */
const getMemberList = ({
  status,
  levelId,
  searchType,
  keywords,
  online,
  userType,
  minBalance,
  maxBalance,
  startDate,
  endDate,
  page,
  size,
  creditStatus,
  feeRule,
  commMode,
  cashRule,
  levelStatus,
  channelId,
  thirdPartyUserName,
  lockStatus,

} = {}) => apiService.post(api.MEMBER_LIST, {
  status,
  levelId,
  searchType,
  keywords,
  online,
  channelId,
  thirdPartyUserName,
  // minBalance: maxBalance ? (minBalance ? minBalance : 0) : undefined,
  minBalance,
  maxBalance: maxBalance || undefined,
  startDate,
  endDate,
  userType: userType || 0,
  page,
  size,
  creditStatus,
  feeRule,
  commMode,
  cashRule,
  levelStatus,
  lockStatus,
});

/**
 * 获取会员详情
 * @return {Promise<*>}
 * @param member_id
 */
const getMemberDetail = params => apiService.post(api.MEMBER_DETAIL, params);
/**
 * 代理上分开启
 * @return {Promise<*>}
 * @param proxyId，status
 */
const getMemberSet = params => apiService.post(api.MEMBER_SET, params);
/**
 * 查询用户的账户安全设置信息
 * @return {Promise<*>}
 * @param member_id
 */
const getMemberSecurity = params => apiService.post(api.MEMBER_SECURITY, params);
/**
 * 清除用户的账户安全设置信息
 * @return {Promise<*>}
 * @param member_id
 */
const clearMemberSecurity = params => apiService.post(api.MEMBER_SECURITY_CLEAR, params);

/**
 * 获取会员银行卡列表
 * @param  {member_id}
 * @return {Promise<*>}
 */
const getMemberBankList = params => apiService.post(api.MEMBER_BANK_LIST, params);
/**
 * 获取会员银行卡记录
 * @param  {member_id}
 * @return {Promise<*>}
 */
const getMemberBankLogs = params => apiService.post(api.MEMBER_BANK_LOGS, params);
/**
 * 获取会员层级调整记录
 * @param  {member_id}
 * @return {Promise<*>}
 */
const getMemberLevelLogs = params => apiService.post(api.MEMBER_LEVEL_LOGS, params);

/**
 * 修改会员银行卡信息
 * @param  {member_id}
 * @return {Promise<*>}
 */
const updateMemberBankcard = params => apiService.post(api.MEMBER_BANK_EDIT, params);
/**
 * 删除会员银行卡
 * @return {Promise<*>}
 * @param userId
 * @param cardId
 * @param remark
 */
const delMemberBankcard = ({ userId, cardId, remark }) => apiService.post(api.MEMBER_BANK_DEL, { userId, cardId, remark });
/**
 * 修改会员密码
 * @param  {member_id}
 * @param  {password}
 * @param  {repassword}
 * @return {Promise<*>}
 */
const updateMemberPass = (params) => {
  const {
    member_id, password, repassword, reason,
  } = params;
  return apiService.post(api.MEMBER_UPDATE_PASS, params);
};
/**
 * 修改会员密码
 * @param  {member_id}
 * @return {Promise<*>}
 */
const updateMemberInfo = params => apiService.post(api.MEMBER_UPDATE_INFO, params);
/**
 * 添加会员备注
 * @param  {member_id}
 * @return {Promise<*>}
 */
const addMemberComment = ({ userId, remark }) => apiService.post(api.MEMBER_ADD_COMMENT, { userId, remark });
/**
 * 添加会员备注2
 * @param  {member_id}
 * @return {Promise<*>}
 */
const addMemberTag = ({ orderId, tag }) => apiService.post(api.MEMBER_ADD_TAG, { orderId, tag });

/**
 * 设置用户或用户组的状态
 * @param ids [Array] 更改状态对应的用户ids
 * @param lockClass
 * @param reason 原因
 * @param type 操作类型：4完全锁定，5间接锁定，6解除锁定
 * @returns {Promise<*>}
 */
const setMembersStatus = ({
  ids, lockClass, reason, type, around,
}) => apiService.post(api.MEMBER_SET_STATUS, {
  userIds: ids.join(','), optType: type, remark: reason, around,
});

/**
 * 配置用户的上级代理
 * @param member_id
 * @param agency_id
 * @returns {Promise<*>}
 */
const updateMembersAgency = ({ userId, proxy }) => apiService.post(api.MEMBER_UPDATE_AGENCY, { userId, proxy });

/**
 * 查看用户的账户信息
 * @returns {Promise<*>}
 * @param params
 */
const getMemberBalance = params => apiService.post(api.MEMBER_BALANCE, params);

/**
 * 同步用户的平台余额信息
 * @param member_id
 * @returns {Promise<*>}
 */
const syncMemberBalance = ({ userId, channelId }) => apiService.post(api.MEMBER_SYNC_BALANCE, { userId, channelId });

/**
 * 用户余额平台转账
 * @param member_id
 * @returns {Promise<*>}
 */
const memberBalanceTransfer = params => apiService.post(api.MEMBER_BALANCE_TRANSFER, params);
/**
 /**
 * 用户余额平台转账
 * @param member_id
 * @returns {Promise<*>}
 */
const memberBalanceRecover = params => apiService.post(api.MEMBER_BALANCE_RECOVER, params);
/**
 * 查询用户财务信息
 * @param search_date
 * @param trade_type
 * @param member_id
 * @returns {Promise<*>}
 */
const getMemberFinance = params => apiService.post(api.MEMBER_FINANCE, params);
/**
 * 查询用户提现流水详情
 * @param member_id
 * @returns {Promise<*>}
 */
const getMemberWithDraw = params => apiService.post(api.MEMBER_WITHDRAW, params);
/**
 * 查询用户交易记录
 * @param params
 * @returns {Promise<*>}
 */
const getMemberTradeList = (params) => {
  let { orderType, subType } = params;
  if (!_.isUndefined(orderType)) {
    if (_.isArray(orderType)) {
      orderType = orderType.join(',');
    }
    params.orderType = orderType;
  }
  if (!_.isUndefined(subType)) {
    if (_.isArray(subType)) {
      subType = subType.join(',');
    }
    params.subType = subType;
  }
  return apiService.post(api.MEMBER_TRADE_LIST, params);
};
/**
 * 导出用户交易记录
 * @param params
 * @returns {Promise<*>}
 */
const getMemberTradeListExport = (params) => {
  let { orderType, subType } = params;
  if (!_.isUndefined(orderType)) {
    if (_.isArray(orderType)) {
      orderType = orderType.join(',');
    }
    params.orderType = orderType;
  }
  if (!_.isUndefined(subType)) {
    if (_.isArray(subType)) {
      subType = subType.join(',');
    }
    params.subType = subType;
  }
  return apiService.post(api.MEMBER_TRADE_LIST_EXPORT, params);
};
/**
 * 导出用户交易记录
 * @param params
 * @returns {Promise<*>}
 */
const exportMemberTradeList = params => apiService.post(api.MEMBER_TRADE_EXPORT_LIST, params);
/**
 * 查询用户登录日志
 * @param params
 * @returns {Promise<*>}
 */
const getMemberLoginLogs = params => apiService.post(api.MEMBER_LOGIN_LOGS, params);
/**
 * 查询后台操作日志
 * @param params
 * @returns {Promise<*>}
 */
const getMemberOperatorLogs = params => apiService.post(api.MEMBER_OPERATOR_LOGS, params);
/**
 * 查询用户操作日志
 * @param params
 * @returns {Promise<*>}
 */
const getMemberSelfOperatorLogs = params => apiService.post(api.MEMBER_OPERATOR_SELF_LOGS, params);
/**
 * 查询后台操作人
 * @param params
 * @returns {Promise<*>}
 */
const getMemberOperatorSelect = params => apiService.post(api.MEMBER_MNGLOG_OPERATOR, params);
/**
 * 查询用户套利
 * @param params
 * @returns {Promise<*>}
 */
const getMemberArbitrage = params => apiService.post(api.MEMBER_ARBITRAGE, params);
/**
 * 查询用户重叠IP
 * @param params
 * @returns {Promise<*>}
 */
const getMemberRepeatIps = params => apiService.post(api.MEMBER_REPEAT_IPS, params);
/**
 * 查询玩家层级列表
 * @param params
 * @returns {Promise<*>}
 */
const getMemberLevelList = params => apiService.post(api.MEMBER_LEVEL_LIST, params);
/**
 * 我的地址列表
 * @param params
 * @returns {Promise<*>}
 */
const getMemberAddressList = params => apiService.post(api.MEMBER_ADDRESS, params);
/**
 * 上分设置记录
 * @param params
 * @returns {Promise<*>}
 */
const getMemberAdjustList = params => apiService.post(api.MEMBER_ADJUSTLIST, params);
/**
 * 上分清算记录
 * @param params
 * @returns {Promise<*>}
 */
const getMemberClearList = params => apiService.post(api.MEMBER_CLEARLIST, params);
/**
 * 代理上分记录
 * @param params
 * @returns {Promise<*>}
 */
const getMemberCreditList = params => apiService.post(api.MEMBER_CREDITLIST, params);
/**
 * 获取玩家账户锁定记录
 * @param lock_state: 1/2 锁定 解锁
 * @param params
 * @returns {Promise<*>}
 */
const getMemberLockLogs = ({ lock_state, ...params }) => apiService.post(api.MEMBER_LOCK_LOGS, { lock_state, ...params });
/**
 * 获取上分清算记录
 * @param params
 * @returns {Promise<*>}
 */
const getMemberCreditClearList = params => apiService.post(api.MEMBER_CREDITCLEAR, params);
const getMemberLogin = data => apiService.post(api.OPERATIONAL_MEMBER_LOGIN, data);
/**
 * 上分汇总记录
 * @param params
 * @returns {Promise<*>}
 */
const getAllrecord = data => apiService.post(api.MEMBER_ALLRECORD, data);
/**
 * 导出会员列表报表
 * @param params
 * @returns {Promise<*>}
 */
const exportMembershipList = params => apiService.post(api.EXPORT_MEMBERSHIP_LIST, params);
/**
 * 导出上分记录相关报表
 * @param params
 * @returns {Promise<*>}
 */
const exportMembersAllRecordList = params => apiService.post(api.MEMBER_ALLRECORD_EXPORT, params);
const exportMembersAllClearList = params => apiService.post(api.MEMBER_CLEAR_EXPORT, params);

/**
 * 清空当前流水限制
 * @param params
 * @returns {Promise<*>}
 */

const emptyFlow = params => apiService.post(api.EMPTY_FLOW_LIMIT, params);

/**
 * 资金流水明细列表
 * @param params
 * @returns {Promise<*>}
 */
const getMenberRunningWaterDetail = params => apiService.post(api.MEMBER_RUNNING_WATER_DETAIL, params);
/**
 * 资金流水调整
 * @param params
 * @returns {Promise<*>}
 */
const memberRunningWaterAdjust = params => apiService.post(api.MEMBER_RUNNING_WATER_ADJUST, params);
/**
 * 资金流水移除
 * @param params
 * @returns {Promise<*>}
 */
const memberRunningWaterRemove = params => apiService.post(api.MEMBER_RUNNING_WATER_REMOVE, params);
/**
 * 资金流水恢复
 * @param params
 * @returns {Promise<*>}
 */
const memberRunningWaterRecover = params => apiService.post(api.MEMBER_RUNNING_WATER_RECOVER, params);


/**
 * 会员代理数据同步
 * @param username
 * @returns {Promise<*|*|*|undefined>}
 */
const memberSyncData = ({ username = 'admin' }) => apiService.post(api.MEMBER_SYNC, { username });

/**
 * 手机邮箱记录
 * @param params
 * @returns {Promise<*|*|*|undefined>}
 */
const memberContactModify = params => apiService.post(api.MEMBER_AGENCY_CONTACT_MODIFY, params);

/**
 * 获取会员上分记录列表
 * @param params
 * @returns {Promise<*>}
 */
const getMemberUpAmountList = params => apiService.post(api.MEMBER_UPAMOUNT_RECORD, params);
/**
 * 批量修改VIP等级
 * @param params
 * @returns {Promise<*>}
 */
const vipBtachUpdate = params => apiService.post(api.VIP_BATCH_UPDATE, params);
/**
 * 批量解锁VIP等级
 * @param params
 * @returns {Promise<*>}
 */
const vipBtachUnlock = params => apiService.post(api.VIP_BATCH_UNLOCK, params);
/**
 * 根据姓名查询会员信息，
 * @param params
 * @returns {Promise<*>}
 */
const vipNameSearch = params => apiService.post(api.VIP_NAME_SEARCH, params);
/**
 * VIP锁定解锁记录
 * @param params
 * @returns {Promise<*>}
 */
const vipLuckRecord = params => apiService.post(api.VIP_LUCK_RECORD, params);

export {
  getMemberList,
  setMembersStatus,
  getMemberDetail,
  getMemberSet,
  getMemberBankList,
  updateMemberBankcard,
  updateMemberPass,
  updateMemberInfo,
  addMemberComment,
  addMemberTag,
  delMemberBankcard,
  updateMembersAgency,
  getMemberBalance,
  syncMemberBalance,
  memberBalanceTransfer,
  getMemberFinance,
  getMemberWithDraw,
  getMemberTradeList,
  getMemberTradeListExport,
  exportMemberTradeList,
  getMemberLoginLogs,
  getMemberCreditClearList,
  getMemberArbitrage,
  getMemberRepeatIps,
  getMemberLevelList,
  getMemberOperatorLogs,
  getMemberLockLogs,
  getMemberSelfOperatorLogs,
  getMemberOperatorSelect,
  memberBalanceRecover,
  getMemberBankLogs,
  getMemberLevelLogs,
  getMemberSecurity,
  clearMemberSecurity,
  getMemberAddressList,
  getMemberAdjustList,
  getMemberClearList,
  getMemberCreditList,
  getMemberLogin,
  getMenberRunningWaterDetail,
  getAllrecord,
  exportMembershipList,
  exportMembersAllRecordList,
  exportMembersAllClearList,
  emptyFlow,
  memberRunningWaterAdjust,
  memberRunningWaterRemove,
  memberRunningWaterRecover,

  memberSyncData,
  memberContactModify,
  getMemberUpAmountList,
  vipBtachUpdate,
  vipBtachUnlock,
  vipNameSearch,
  vipLuckRecord,
};
